class AgendasController < ApplicationController

  layout 'application'

  uses_tiny_mce(:options => {:theme => 'advanced',
    :browsers => %w{msie gecko},
    :theme_advanced_toolbar_location => "top",
    :theme_advanced_toolbar_align => "left",
    :theme_advanced_resizing => true,
    :theme_advanced_resize_horizontal => false,
    :paste_auto_cleanup_on_paste => true,
    :theme_advanced_buttons1 => %w{bold italic underline strikethrough separator justifyleft justifycenter justifyright separator bullist numlist forecolor backcolor separator link unlink undo redo separator pastetext pasteword},
    :theme_advanced_buttons2 => [],
    :theme_advanced_buttons3 => [],
    :plugins => %w{contextmenu paste}},
    :only => [:novoAgendas, :editarAgendas])

  def index
    listarAgendas
    render :action => 'listarAgendas'
  end

  def listarAgendas
    @agenda_pages, @agendas = paginate :agendas, :order => "data DESC, hora DESC", :per_page => 30
  end

  def novoAgendas
    @page = params[:page]
    @agenda = Agenda.new
  end

  def inserirAgendas
    @page = params[:page]
    @agenda = Agenda.new(params[:agenda])
    
    if @agenda.save
      redirect_to :action => 'listarAgendas', :page => @page
    else
      render :action => "novoAgendas"
    end
  end

  def editarAgendas 
    @page = params[:page]
    @agenda = Agenda.find(params[:id])
  end

  def atualizarAgendas
    @page = params[:page]
    @agenda = Agenda.find(params[:id])
    if @agenda.update_attributes(params[:agenda])
      flash[:notice] = 'Agenda foi editado com sucesso.'
      redirect_to :action => 'verAgendas', :id => @agenda, :page => @page
    else
      render :action => 'editarAgendas'
    end
  end

  def verAgendas
    @page = params[:page]
    @agenda = Agenda.find(params[:id])
  end

  def apagarAgendas
    @page = params[:page]
    Agenda.find(params[:id]).destroy
    redirect_to :action => 'listarAgendas', :page => @page
  end
end
